// 列表加载
get();

function get() {
    $.ajax({
        url: "/my/article/category",
        success: function (res) {
            if (res.status == 0) {
                let str = "";
                res.data.forEach(item => {
                    str += `<tr>
                                <td>${item.name}</td>
                                <td>${item.alias}</td>
                                <td>
                                    <button type="button" class="layui-btn layui-btn-xs btnEdit" data-id="${item.Id}">编辑</button>
                                    <button type="button" class="layui-btn layui-btn-xs layui-btn-danger btnDelete" data-id="${item.Id}">删除</button>
                                </td>
                            </tr>`;
                });
                $("tbody").html(str);
            }
        }
    });
}

// 删除  (四种方法)
let layer = layui.layer;
$("tbody").on("click", ".btnDelete", function () {
    // 不推荐,构成闭包!
    // 1.获取点击对应id
    let id = $(this).attr("data-id");
    layer.confirm("你确定要删除么?", function (index) {
        // 2.发送请求
        $.ajax({
            url: "/my/article/deletecate/" + id,
            success: function (res) {
                layer.msg(res.message);
                if (res.status == 0) {
                    get();
                }
            }
        })
    })
})